<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page import="net.groupme.gui.rendering.constants.RENDERING_CONSTANTS"%>
<%@page import="java.util.List"%>
<%@page import="net.groupme.game.GroupMeGame"%>
<%@page import="net.groupme.game.persistence.GamePersistence"%>
<%@page import="net.groupme.game.GAME_CONSTANTS"%>
<%@page import="net.groupme.game.GameManager"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

	<title>Welcome to GroupMe! ...where Semantic Web meets Web 2.0 - [Home]</title>
	<!-- meta tags, link to css:  -->
	<%@ include file="./jsp-includes/metaheader.jsp" %>
	
	<!--  Ajax-Includes -->
	<script type='text/javascript' src='<%= request.getContextPath()%>/dwr/interface/DWRGameManager.js'></script>
    <script type='text/javascript' src='./dwr/engine.js'></script>
	<script type='text/javascript' src='./dwr/util.js'> </script>
	<script src="./scriptaculous/prototype.js" type="text/javascript"></script>
	<script src="./scriptaculous/scriptaculous.js" type="text/javascript"></script>
    
    <script type="text/javascript" language="javascript">
    <!--//--><![CDATA[//><!--
	
	//init stuff:		
	function init() {
		DWRUtil.useLoadingMessage();
	}

	//--><!]]>
    </script>
</head>

<body onload="init()">
	<!-- title image, logo:  -->
	<div id="header">
		<%@ include file="./game-includes/titleheader.jsp" %>
	</div>
	
	<!-- Menu: -->
	<div id="menu">
		<%@ include file="./jsp-includes/menu.jsp" %>
	</div>

	<!-- content -->
	<div id="main">
			<% 	Long id = GameManager.getInstance().TEMP_ID_TO_DB_ID_MAP.get(Long.parseLong(request.getAttribute(VIEW_VOCABULARY.PARAMETER_GAME_ID).toString()));
				GroupMeGame theGame = GamePersistence.readGameFromDB(id);  %>
			<h1>Congratulations! You scored <%= theGame.getOverallScore() %> points!</h1><br/><br/>
			<div id="highscore">
				<h2>Highscores</h2><br/><br/>
				<h3 style="margin-bottom: -1em; margin-top: 1em;">Daily Highscore</h3>
				<table>
				<colgroup><col width="5%"/><col width="10%"/><col width="30%"/><col width="20%"/></colgroup>
				<tr><td><strong>Rank</strong></td><td><strong>Score</strong></td><td><strong>Player (Group)</strong></td><td><strong>Topic</strong></td></tr>
				<%	List<GroupMeGame> games = GamePersistence.getTodaysHighScore(GAME_CONSTANTS.HIGHSCORE_TOP_K); 
					int rank = 0;
					for(GroupMeGame game: games){
						rank++;
						String boldStart = ""; String boldEnd = "";
						if(game.equals(theGame)){
							boldStart = "<strong>"; boldEnd = "</strong>";
						}%>
						<tr>
							<td><%= boldStart + rank + "." + boldEnd %></td>
							<td><%= boldStart + game.getOverallScore() + boldEnd %></td>
							<td>
								<%= boldStart + game.getCreator().getUserName() %>
								(<a href="<%= game.getCreatorsGroup().getURI() %>">group</a>) 
								& 
								<%= game.getOpponent().getUserName() %>
								(<a href="<%= game.getOpponentsGroup().getURI() %>">group</a>) <%= boldEnd %>
							</td>
							<td><%= boldStart + game.getGametopic() + boldEnd %></td>
						</tr>
				<%} %>
				</table>
				
				<h3 style="margin-bottom: -1em; margin-top: 1em;">Overall CeBIT Highscore</h3>
				<table>
				<colgroup><col width="5%"/><col width="10%"/><col width="30%"/><col width="20%"/></colgroup>
				<tr><td><strong>Rank</strong></td><td><strong>Score</strong></td><td><strong>Player (Group)</strong></td><td><strong>Topic</strong></td></tr>
				<%	games = GamePersistence.getHighScore(GAME_CONSTANTS.HIGHSCORE_TOP_K); 
					rank = 0;
					for(GroupMeGame game: games){
						rank++;
						String boldStart = ""; String boldEnd = "";
						if(game.equals(theGame)){
							boldStart = "<strong>"; boldEnd = "</strong>";
						}%>
						<tr>
							<td><%= boldStart + rank + "." + boldEnd %></td>
							<td><%= boldStart + game.getOverallScore() + boldEnd %></td>
							<td>
								<%= boldStart + game.getCreator().getUserName() %>
								(<a href="<%= game.getCreatorsGroup().getURI() %>">group</a>) 
								& 
								<%= game.getOpponent().getUserName() %>
								(<a href="<%= game.getOpponentsGroup().getURI() %>">group</a>) <%= boldEnd %>
							</td>
							<td><%= boldStart + game.getGametopic() + boldEnd %></td>
						</tr>
				<%} %>
				</table>
			</div>
			<h2>Your results</h2><br/><br/>
			<p>
			<strong>Your groups:</strong> 
				<a href="<%= theGame.getCreatorsGroup().getURI() %>"><%= theGame.getCreator().getUserName() %>'s group</a>, 
				<a href="<%= theGame.getOpponentsGroup().getURI() %>"><%= theGame.getOpponent().getUserName() %>'s group</a><br/><br/>
			<strong>Your Score: </strong> <%= theGame.getOverallScore() %> <br/><br/>
			
			<strong>Your rankings: </strong><br/>
			<span style="padding-left: 2em"><strong>Rank <%= GamePersistence.getGameRankToday(theGame) %></strong> in <i>Daily Highscore</i>.</span><br/>
			<span style="padding-left: 2em"><strong>Rank <%= GamePersistence.getGameRankOverall(theGame) %></strong> in <i>Overall CeBIT Highscore</i>.</span><br/>
			
			</p><br/><br/>
			<h2>Start new game</h2>
			<p>
				<strong><a href="<%= request.getContextPath() + "/ggmain.jsp"%>" title="Start a new GroupMe! Game">Start a new game...</a></strong>
			</p>

		<form name="startGame" action="<%= VIEW_VOCABULARY.ACTION_START_GAME%>"> 
			<input id="gameIdInput" type="hidden" name="<%= VIEW_VOCABULARY.PARAMETER_GAME_ID %>" value="<%=request.getAttribute(VIEW_VOCABULARY.PARAMETER_GAME_ID) %>"/> 
		</form>
		<br/><br/><br/><br/>
		<!-- footer -->
		<div id="footer">
			<%@ include file="./jsp-includes/footer.jsp" %>
		</div>
	</div>
	
</body>
</html>